<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>UMD Room Finder</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script type="text/javascript">

        function getRooms(building){
            
            if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp=new XMLHttpRequest();
              }
            else
              {// code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            xmlhttp.onreadystatechange=function()
              {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                document.getElementById("buildingDiv").innerHTML=xmlhttp.responseText;
                }
              }
            xmlhttp.open("GET","updateRooms.php?Building="+building,true);
            xmlhttp.send();
        };
        
<!--        getRooms(document.getElementById("building").value));-->
        getRooms("Heller Hall");
</script>

  </head>
  <body>

<style type="text/css">
body
{
background-color:#e5f5ff;
background-image:url(http://img.photobucket.com/albums/v627/lovkurama/Screenshot2011-10-03at53227PM.png);
background-repeat:repeat-x;
}
div.banner
{
text-align:left;
}
</style>

<div class="banner">

<img src="http://img.photobucket.com/albums/v627/lovkurama/Screenshot2011-10-11at103904AM.png" height=30>


<h1>Room Finder</h1>
<br>

<?php
	//make connection to server
	$link = mysql_connect('localhost', 'pott0180', 'ckersixt');
	if(!$link) {
		die('Could not connect: ' . mysql_error());
	}

	//select database
	$db_selected = mysql_select_db('soloono_roomFinder', $link);
	if (!$db_selected) {
		die('Cant use db soloono_roomFinder: ' . mysql_error());
	}



        $building_result = sprintf("SELECT name FROM Building");
        $building_query = mysql_query($building_result);

        echo "Your Location";

        echo "<p>     <h5>Building:</h5>";

        echo "</p>";

        echo "Your Destination";
        echo "<p>     <h5>Room:</h5>";

        echo "</p>        ";

        
        //Create Form and populate from database
        echo '<form action="results.php" method="get">';
        echo '<select name="Building" id="building" onchange="getRooms(this.value)">';
        while($building_array = mysql_fetch_array($building_query))
          {
          echo '<option value="'.$building_array["name"].'">'.$building_array["name"].'</option>';
          }
        echo "</select>";

        //Populate second select from database
        echo "<div id='buildingDiv'>";
			// populated in updateRooms.php
        echo '</div>';

        echo '<INPUT TYPE="image" SRC="http://img.photobucket.com/albums/v627/lovkurama/button-1.png" width=100 ALT="Submit Form">';
    
        echo '</form>';

        mysql_close($link);


       ?>

        <br />



<br><br>


</body>
</html>
